Closet = class('Closet', World):include(Stateful)

function Closet:initialize(lat, long, ele, temp, ene, fri, res, feat, sea, seed)
    World.initialize(self, lat, long, ele, temp, ene, fri, res, feat, sea, seed, true)    
    
    self:add_floor(lat, long, ele, temp, ene, fri, res, feat, sea)
    
end

function Closet:add_floor(level, lat, long, ele, temp, ene, fri, res, feat, sea)
    local lat = self.data.stats.lat or lat
    local long = self.data.stats.long or long
    local ele = self.data.stats.ele or ele
    local temp = self.data.stats.temp or temp
    local ene = self.data.stats.ene or ene
    local fri = self.data.stats.fr or fri
    local res = self.data.stats.res or res
    local feat = self.data.stats.feat or feat
    local sea = self.data.stats.sea or sea

    if lat and long and ele and temp and ene and fri and res and feat and sea then
            local level = level or 1
            local closet_stats = love.thread.getChannel("closet_stats")
            closet_stats:push(self.data.stats)
            local closet_seed = love.thread.getChannel("closet_seed")
            if game.debug == true then		
                    self.data.seed = 1		
            end
            closet_seed:push(self.data.seed)
            local closet_level = love.thread.getChannel("closet_level")
            closet_level:push(level)
            self.clos_thread = love.thread.newThread('closet_generator.lua')
            self.clos_thread:start()
    end
end

function Closet:add_tile(tile)
    print("adding tile " .. tile.x .. " x " .. tile.y .. " y " .. tile.type .. " type" )
    if not self.data.grid then self.data.grid = {} end
    if not self.data.grid[tile.z] then self.data.grid[tile.z] = {} end
    if not self.data.grid[tile.z][tile.y] then self.data.grid[tile.z][tile.y] = {} end
    self.data.grid[tile.z][tile.y][tile.x] = Tile:new(tile.x, tile.y, tile.z, tile.type)
    
end